import type { ProTableProps } from './typing.ts'
import { useSettingColumn } from './basic-table/composables/setting-column.ts'

/**
 * @ClassName: context
 * @Description: // 依赖注入
 * @Author: Ellwood
 * @CreateDate: 2024/2/27 - 7:41
 * @Version: V1.0.0
 */
function tableState(props: ProTableProps) {
  const columns = computed(() => props.columns)
  const options = computed(() => props.options)

  const settingColumns = useSettingColumn(props)

  return {
    columns,
    options,
    settingColumns,
  }
}

const [useProTableProvider, useProTableInject] = createInjectionState(tableState)

export function useProTableState(): ReturnType<typeof tableState> {
  return (
    useProTableInject() ?? {
      columns: computed(() => []),
      options: computed(() => ({ reload: true, setting: true })),
      settingColumns: {} as any,
    }
  )
}

export { useProTableProvider }
